package com.microsec.iot.utils;

import java.util.HashMap;
import java.util.Map;

import org.apache.http.HttpResponse;

public class IotHttpUtil {
	
	private static HttpsUtil httpsUtil = new HttpsUtil();
	private static String accessToken = null;
	private static String appId = Constant.APPID;
	private static Map<String, String> headerMap = new HashMap<>();
    
	static{
		try {
			// Two-Way Authentication
			httpsUtil.initSSLConfigForTwoWay();
			accessToken = LoginUtil.login(httpsUtil);
			headerMap.put(Constant.HEADER_APP_KEY, appId);
			headerMap.put(Constant.HEADER_APP_AUTH, "Bearer" + " " + accessToken);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static HttpResponse sendRequest(String url,String jsonRequest) {
		return httpsUtil.doPostJson(url, headerMap, jsonRequest);
	}
}
